/*
ID:luongho3
LANG:C++
TASK:range
*/
#include <iostream>
#include <fstream>
using namespace std;
#define MAXN 251
ifstream fin("range.in");
ofstream fout("range.out");
int n, bigsqr[MAXN][MAXN],nsqr[MAXN];
char area[MAXN][MAXN];
int smaller(int a,int b) {
    return a<b?a:b;
}
int main() {
    fin >> n;
    int i,j,k,l,sz;
    for (i=0;i<n;++i) {
        fin >> area[i];
        nsqr[i+1] = 0;
    }

    for (i=0;i<n;++i) {
        for (j=0;j<n;++j) {
            if (i==0 || j==0) {
               if (area[i][j]=='0') {
                  bigsqr[i][j] = 0;
               }
               else {
                    bigsqr[i][j] = 1;
                    nsqr[bigsqr[i][j]]++;
               }
            }
            else {
                 if (area[i][j]=='0') {
                    bigsqr[i][j] = 0;
                 }
                 else {
                     int tmp = bigsqr[i-1][j] < bigsqr[i][j-1] ? bigsqr[i-1][j] : bigsqr[i][j-1];
                     tmp = tmp < bigsqr[i-1][j-1] ? tmp : bigsqr[i-1][j-1];
                     bigsqr[i][j] = tmp + 1;
                     nsqr[bigsqr[i][j]]++;
                 }
            }
        }
    }
    /*for (i=0;i<n;++i) {
        for (j=0;j<n;++j) {
            for (k=2;k<=bigsqr[i][j];++k) {
                nsqr[k]++;
            }
        }
    }*/
    for (i=n-1;i>=2;--i) {
        nsqr[i] += nsqr[i+1];
    }
    for (i=2;i<=n;++i) {
        if (nsqr[i]>0) {
           fout << i << " " << nsqr[i] << "\n";
        }
    }
    return 0;
}
